package com.fstec.ks.master.bean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import com.fstec.ks.master.vo.ServerRoundVO;

public class ServerRoundHolder {
	private String key;
	private Date beginTime;
	private Date endTime;
	// key: examServerId
	private ConcurrentHashMap<String, ServerRoundVO> serverRoundRef=new ConcurrentHashMap<String, ServerRoundVO>();
	private ArrayList<ServerRoundVO> serverRounds=new ArrayList<ServerRoundVO>();
	
	public ServerRoundHolder(String key, Date roundBeginTime, Date roundEndTime) {
		this.key=key;
		this.beginTime=roundBeginTime;
		this.endTime=roundEndTime;
	}

	public String getKey() {
		return key;
	}

	public Date getBeginTime() {
		return beginTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void addServerRound(ServerRoundVO serverRoundVo) {
		String id=serverRoundVo.getExamServerId();
		ServerRoundVO oldRound=serverRoundRef.get(id);
		if(oldRound==null){
			serverRoundRef.put(id, serverRoundVo);
			serverRounds.add(serverRoundVo);
		}else{
			oldRound.setBackupTime(serverRoundVo.getBackupTime());
			oldRound.setExamineeCount(serverRoundVo.getExamineeCount());
			oldRound.setLoginCount(serverRoundVo.getLoginCount());
			oldRound.setPaperDown(serverRoundVo.getPaperDown());
			oldRound.setRoomCount(serverRoundVo.getRoomCount());
			oldRound.setRoomSignCount(serverRoundVo.getRoomSignCount());
			oldRound.setSubmitCount(serverRoundVo.getSubmitCount());
			oldRound.setUploadTime(serverRoundVo.getUploadTime());
		}
	}
	
	public List<ServerRoundVO> allServerRounds(){
		return this.serverRounds;
	}
	
	public ServerRoundVO getServerRound(String id){
		return this.serverRoundRef.get(id);
	}
}
